<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>{$smarty} reserved variable</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<link rel="home" href="index.html" title="Smarty 3 Manual">
<link rel="up" href="language.variables.html" title="Chapter 4. Variables">
<link rel="prev" href="language.config.variables.html" title="Variables loaded from config files">
<link rel="next" href="language.modifiers.html" title="Chapter 5. Variable Modifiers">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">{$smarty} reserved variable</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="language.config.variables.html">Prev</a> </td>
<th width="60%" align="center">Chapter 4. Variables</th>
<td width="20%" align="right"> <a accesskey="n" href="language.modifiers.html">Next</a>
</td>
</tr>
</table>
<hr>
</div>
<div class="sect1" title="{$smarty} reserved variable">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="language.variables.smarty"></a>{$smarty} reserved variable</h2></div></div></div>
<p>
  The PHP reserved <em class="parameter"><code>{$smarty}</code></em> variable can be used to
  access several environment and request variables.
  The full list of them follows.
 </p>
<div class="sect2" title="Request variables">
<div class="titlepage"><div><div><h3 class="title">
<a name="language.variables.smarty.request"></a>Request variables</h3></div></div></div>
<p>
   The <a class="ulink" href="http://php.net/reserved.variables" target="_top">request variables
   </a> such as <code class="literal">$_GET</code>, <code class="literal">$_POST</code>,
   <code class="literal">$_COOKIE</code>, <code class="literal">$_SERVER</code>,
   <code class="literal">$_ENV</code> and <code class="literal">$_SESSION</code>
   can be accessed as demonstrated in the examples below:
  </p>
<div class="example">
<a name="id347572"></a><p class="title"><b>Example 4.8. Displaying request variables</b></p>
<div class="example-contents"><pre class="programlisting">

{* display value of page from URL ($_GET) http://www.example.com/index.php?page=foo *}
{$smarty.get.page}

{* display the variable "page" from a form ($_POST['page']) *}
{$smarty.post.page}

{* display the value of the cookie "username" ($_COOKIE['username']) *}
{$smarty.cookies.username}

{* display the server variable "SERVER_NAME" ($_SERVER['SERVER_NAME'])*}
{$smarty.server.SERVER_NAME}

{* display the system environment variable "PATH" *}
{$smarty.env.PATH}

{* display the php session variable "id" ($_SESSION['id']) *}
{$smarty.session.id}

{* display the variable "username" from merged get/post/cookies/server/env *}
{$smarty.request.username}

   </pre></div>
</div>
<br class="example-break"><div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">Note</h3>
<p>
    For historical reasons <em class="parameter"><code>{$SCRIPT_NAME}</code></em> is
    short-hand for <em class="parameter"><code>{$smarty.server.SCRIPT_NAME}</code></em>.
   </p>
<pre class="programlisting">

&lt;a href="{$SCRIPT_NAME}?page=smarty"&gt;click me&lt;/a&gt;
&lt;a href="{$smarty.server.SCRIPT_NAME}?page=smarty"&gt;click me&lt;/a&gt;

</pre>
</div>
<div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">Note</h3>
<p>
    Although Smarty provides direct access to PHP super globals for convenience, it should be used with caution. Directly accessing super globals mixes underlying application code structure with templates. A good practice is to assign specific needed values to template vars.
  </p>
</div>
</div>
<div class="sect2" title="{$smarty.now}">
<div class="titlepage"><div><div><h3 class="title">
<a name="language.variables.smarty.now"></a>{$smarty.now}</h3></div></div></div>
<p>
   The current <a class="ulink" href="http://php.net/function.time" target="_top">timestamp</a>
   can be accessed with <em class="parameter"><code>{$smarty.now}</code></em>.
   The  value reflects the number of
   seconds passed since the so-called Epoch on January 1, 1970,
   and can be passed directly to the
   <a class="link" href="language.modifier.date.format.html" title="date_format"><code class="varname">date_format</code>
   </a> modifier for display. Note that
   <a class="ulink" href="http://php.net/function.time" target="_top"><code class="varname">time()</code></a>
    is called on each invocation; eg a script that takes three seconds to execute
    with a call to <em class="parameter"><code>$smarty.now</code></em> at start and end
    will show the three second difference.
  </p>
<div class="informalexample"><pre class="programlisting">

{* use the date_format modifier to show current date and time *}
{$smarty.now|date_format:'%Y-%m-%d %H:%M:%S'}

   </pre></div>
<p>
  </p>
</div>
<div class="sect2" title="{$smarty.const}">
<div class="titlepage"><div><div><h3 class="title">
<a name="language.variables.smarty.const"></a>{$smarty.const}</h3></div></div></div>
<p>
   You can access PHP constant values directly. See also <a class="link" href="smarty.constants.html" title="Chapter 12. Constants">smarty constants</a>.
   </p>
<div class="informalexample"><pre class="programlisting">

&lt;?php
// the constant defined in php
define('MY_CONST_VAL','CHERRIES');
?&gt;

</pre></div>
<p>Output the constant in a template with</p>
<div class="informalexample"><pre class="programlisting">

{$smarty.const.MY_CONST_VAL}

</pre></div>
<div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">Note</h3>
<p>
  Although Smarty provides direct access to PHP constants for convenience,
  it is typically avoided as this is mixing underlying application
  code structure into the templates.
  A good practice is to assign specific needed values to template vars.  
</p>
</div>
</div>
<div class="sect2" title="{$smarty.capture}">
<div class="titlepage"><div><div><h3 class="title">
<a name="language.variables.smarty.capture"></a>{$smarty.capture}</h3></div></div></div>
<p>
   Template output captured via the built-in
   <a class="link" href="language.function.capture.html" title="{capture}">
   <code class="varname">{capture}..{/capture}</code></a> function can be accessed
   using the <em class="parameter"><code>{$smarty.capture}</code></em> variable.
    See the <a class="link" href="language.function.capture.html" title="{capture}">
    <code class="varname">{capture}</code></a> page for more information.
  </p>
</div>
<div class="sect2" title="{$smarty.config}">
<div class="titlepage"><div><div><h3 class="title">
<a name="language.variables.smarty.config"></a>{$smarty.config}</h3></div></div></div>
<p>
   <em class="parameter"><code>{$smarty.config}</code></em> variable can be used to refer
   to loaded <a class="link" href="language.config.variables.html" title="Variables loaded from config files">config variables</a>.
   <em class="parameter"><code>{$smarty.config.foo}</code></em> is a synonym for
   <em class="parameter"><code>{#foo#}</code></em>. See the
   <a class="link" href="language.function.config.load.html" title="{config_load}">{config_load}</a> page
   for more info.
  </p>
</div>
<div class="sect2" title="{$smarty.section}">
<div class="titlepage"><div><div><h3 class="title">
<a name="language.variables.smarty.loops"></a>{$smarty.section}</h3></div></div></div>
<p>
   The <em class="parameter"><code>{$smarty.section}</code></em> variables can be used to refer to
   <a class="link" href="language.function.section.html" title="{section},{sectionelse}"><code class="varname">{section}</code></a>
   loop properties. These have some very useful values such as
   <code class="varname">.first</code>, <code class="varname">.index</code>, etc.
  </p>
<div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">Note</h3>
<p>
    The <code class="varname">{$smarty.foreach}</code> variable is no longer used with the new <a class="link" href="language.function.foreach.html" title="{foreach},{foreachelse}"><code class="varname">{foreach}</code></a> syntax,
    but is still supported with Smarty 2.x style foreach syntax.
  </p>
</div>
</div>
<div class="sect2" title="{$smarty.template}">
<div class="titlepage"><div><div><h3 class="title">
<a name="language.variables.smarty.template"></a>{$smarty.template}</h3></div></div></div>
<p>
   Returns the name of the current template being  processed (without the directory).
  </p>
</div>
<div class="sect2" title="{$smarty.template_object}">
<div class="titlepage"><div><div><h3 class="title">
<a name="language.variables.smarty.template_object"></a>{$smarty.template_object}</h3></div></div></div>
<p>
   Returns the template object of the current template being  processed.
  </p>
</div>
<div class="sect2" title="{$smarty.current_dir}">
<div class="titlepage"><div><div><h3 class="title">
<a name="language.variables.smarty.current_dir"></a>{$smarty.current_dir}</h3></div></div></div>
<p>
    Returns the name of the directory for the current template being processed.
   </p>
</div>
<div class="sect2" title="{$smarty.version}">
<div class="titlepage"><div><div><h3 class="title">
<a name="language.variables.smarty.version"></a>{$smarty.version}</h3></div></div></div>
<p>
   Returns the version of Smarty the template was compiled with.
  </p>
<pre class="programlisting">

&lt;div id="footer"&gt;Powered by Smarty {$smarty.version}&lt;/div&gt;

</pre>
</div>
<div class="sect2" title="{$smarty.block.child}">
<div class="titlepage"><div><div><h3 class="title">
<a name="language.variables.smarty.block.child"></a>{$smarty.block.child}</h3></div></div></div>
<p>
   Returns block text from child template.
   See <a class="link" href="advanced.features.template.inheritance.html" title="Template Inheritance">Template interitance</a>.
  </p>
</div>
<div class="sect2" title="{$smarty.block.parent}">
<div class="titlepage"><div><div><h3 class="title">
<a name="language.variables.smarty.block.parent"></a>{$smarty.block.parent}</h3></div></div></div>
<p>
   Returns block text from parent template.
   See <a class="link" href="advanced.features.template.inheritance.html" title="Template Inheritance">Template interitance</a>
  </p>
</div>
<div class="sect2" title="{$smarty.ldelim}, {$smarty.rdelim}">
<div class="titlepage"><div><div><h3 class="title">
<a name="language.variables.smarty.ldelim"></a>{$smarty.ldelim}, {$smarty.rdelim}</h3></div></div></div>
<p>
   These variables are used for printing the left-delimiter and right-delimiter
   value literally, the same as <a class="link" href="language.function.ldelim.html" title="{ldelim},{rdelim}">
   <code class="varname">{ldelim},{rdelim}</code></a>.
  </p>
<p>
   See also
   <a class="link" href="language.variables.html#language.assigned.variables" title="Variables assigned from PHP">assigned variables</a> and
   <a class="link" href="language.config.variables.html" title="Variables loaded from config files">config variables</a>
  </p>
</div>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="language.config.variables.html">Prev</a> </td>
<td width="20%" align="center"><a accesskey="u" href="language.variables.html">Up</a></td>
<td width="40%" align="right"> <a accesskey="n" href="language.modifiers.html">Next</a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Variables loaded from config files </td>
<td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td>
<td width="40%" align="right" valign="top"> Chapter 5. Variable Modifiers</td>
</tr>
</table>
</div>
</body>
</html>
